package com.auth.manage.user.domain.service.query.strategy;

import com.auth.manage.common.user.api.constant.UserQueryStrategyCode;
import com.auth.manage.common.user.api.request.condition.UserQueryByTelephoneCondition;
import com.auth.manage.common.user.api.request.condition.UserQueryCondition;
import com.auth.manage.user.domain.entity.User;
import com.auth.manage.user.domain.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;


@Component
@RequiredArgsConstructor
public class UserQueryByTelephoneImpl implements UserQueryStrategy {

    private final UserService userService;

    @Override
    public UserQueryStrategyCode getStrategyCode() {
        return UserQueryStrategyCode.QUERY_BY_TELEPHONE;
    }

    @Override
    public Collection<User> query(UserQueryCondition condition) {
        UserQueryByTelephoneCondition userQueryByTelephoneCondition = (UserQueryByTelephoneCondition) condition;
        User user = userService.lambdaQuery()
                .eq(User::getTelephone, userQueryByTelephoneCondition.getTelephone())
                .one();
        return Collections.singleton(user);
    }
}
